package test.testtc;

/**
 * @Description
 * @Author Firenut
 * @Date 2023-09-10 20:19
 */
public class T1_pathNumber {
    int ans = 0,count0 = 0,count1 = 0;

    public int pathNumber (TreeNode root) {
        // write code here
        dfs(root);
        return ans;
    }

    void dfs(TreeNode root){
        if(root == null){
            if(count0 < count1) ans++;
            return;
        }

        // 记录当前层的数字个数
        if(root.val == 0) count0++;
        else count1++;

        // 往左子树查找
        dfs(root.left);

        dfs(root.right);

        if(root.val == 0) count0--;
        else count1--;

    }
}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}